 %include header libraryName=libraryName
    <script type="text/javascript">
        //<!--
        $(document).ready(function() {
            $('.checkAll').click(function() {
                var checked = $(this).attr('checked');
                $('.cardCheckbox').attr('checked', checked);
            });
            
            $('input[type=checkbox]').click(function() {
                $('.numSelected').text($('.cardCheckbox:checked').length);
            });
            
            $('.numSelected').text($('.cardCheckbox:checked').length); // In case they refreshed the page or something
        });
        
        function generateCards() {
            var codes = [];
            $('.cardCheckbox:checked').each(function() {
                codes.push({code: parseInt($(this).parents('tr').find('.id').text(), 10),
                             data: $(this).parents('tr').find('.name').text()});
            });
            window.location = '/administration/generateCards.pdf?ids=' + encodeURIComponent(JSON.stringify(codes)) + '';
        }
        
        function generateLibrarianCardSheet() {
            var codes = [];
            $('.cardCheckbox:checked').each(function() {
                codes.push({code: parseInt($(this).parents('tr').find('.id').text(), 10),
                             data: $(this).parents('tr').find('.name').text()});
            });
            window.location = '/administration/generateLibrarianCardSheet.pdf?ids=' + encodeURIComponent(JSON.stringify(codes)) + '';
        }
        //-->
    </script>
    <h2>Select Which Users to Print Cards for (<span class="numSelected">0</span> selected)</h2>
    
    <a href="/administration">Administration Home</a>
    <div class="bordered">
        <div>
            <button onclick="generateCards()">Generate Cards</button>
            <button onclick="generateLibrarianCardSheet()">Generate Librarian Card Sheet</button>
        </div>
        <table width="100%">
            <thead>
                <tr>
                    <th><input type="checkbox" class="checkAll" /></th>
                    <th>ID</th>
                    <th>Name</th>
                </tr>
            </thead>
            <tbody>
            %for i, user in zip(range(len(users)), users):
                <tr>
                  <td><input type="checkbox" class="cardCheckbox" /></td>
                  <td class="id">{{user.get('id')}}</td>
                  <td class="name">{{user.get('name', '').encode('utf-8')}}</td>
                </tr>
            %end
            </tbody>
        </table>
        <div>
            <button onclick="generateCards()">Generate Cards</button>
            <button onclick="generateLibrarianCardSheet()">Generate Librarian Card Sheet</button>
        </div>
        <div><a href="/logout">Logout</a></div>
    </div>
%include footer